package com.sm.honkon.data.bean

import android.os.Parcelable
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.Index
import androidx.room.PrimaryKey
import com.afollestad.date.year
import com.sm.honkon.app.ext.getTimeFormat
import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize
import java.util.*

/**
 * @description
 * @author csw
 * @date 2021-05-03
 */
@Parcelize
@Entity(tableName = "customers", indices = [Index(value = ["id"], unique = true)])
data class CustomerEntity(
    //序号
    @PrimaryKey(autoGenerate = false) var uid: Long,
    var id: String = Calendar.getInstance().timeInMillis.getTimeFormat("yyyyMMddhhmmss"),
    var name: String = "",
    var sex: Byte = 0,//0 男， 1 女
    var blood: String = "",
    var mobile: String = "",
    var first_treatment_conetnt: String = "",
    var last_treatment_conetnt: String = "",
    var treatment_count: Int = 0,
    var emergencyCall1: String = "",
    var emergencyCall2: String = "",
    var origin: String = "",//籍贯
    var ethnic: String = "",//民族
    var birthday: String = "",//出生年月
    var occupation: String = "",//职业
    var address: String = "",
    var firstTime: String = "",
    var lastTime: String = "",
    var historyOfPastIllness: String = "",//既往史
    var allergicHistory: String = "",//过敏史
    var chiefComplaint: String = "",//主诉
    var handleId: Long = -1,
    var handleName: String = "admin"
) : Parcelable {
    @IgnoredOnParcel
    @Ignore
    val age: Int = Calendar.getInstance().year - (birthday.split("/").firstOrNull()?.toIntOrNull() ?: 0)
    @IgnoredOnParcel
    @Ignore
    val info: String = "$name $sexShow ${age}岁 $mobile"
    val sexShow
        get() = if (sex > 0) "女" else "男"


    fun uidShow(): String {
        return uid.toString()
    }

    fun setFirstTime(): CustomerEntity {
        firstTime = Calendar.getInstance().timeInMillis.getTimeFormat("yyyy-MM-dd hh:mm:ss")
        return this
    }
}